//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<IScene.cpp>
///	@path	~/src/scene/
///	@date	2007/10/17
///	@desc	Scene interface.

#include "config/config.h"
#include "config/os.h"

#include "graphics/IGeometry.h"
#include "graphics/IModel.h"

#include "scene/IScene.h"
#include "scene/ILive.h"

namespace xeres {

	IMPL_IOBJECT_INTERFACE( IScene );

	// ctor
	IScene::IScene( void )
	{
	}

	// dtor
	IScene::~IScene( void )
	{
	}
	// CreateLive
	RefPass<ILive> IScene::CreateLive( ResourceLoader * loader , RefWeak<IData> res )
	{
		WString classname , model;
		if( ! res->GetAttribute( _S("class") , classname ) )
		{
			TRACE_ERROR( _S("XSimple::Initialize: Failed to get 'class' attribute in ILive definition.") );
			return NULL;
		}

		if( ! res->GetAttribute( _S("model") , model ) )
		{
			TRACE_ERROR( _S("XSimple::Initialize: Failed to get 'model' attribute in ILive definition.") );
			return NULL;
		}

		RefPass<IData> model_data = loader->OpenData( model );
		if( model_data.IsNull() )
		{
			TRACE_ERROR( _S("XSimple::Initialize: Failed to get model data of ILive.") );
			return NULL;
		}

		// create all lives
		RefPass<ILive> newLive = ObjectFactory::CreateObject( classname );
		RefPass<IModel> imodel = loader->LoadModel( RefWeak<IData>( model_data ) );
		newLive->AttachModel( RefWeak<IModel>( imodel ) );
		return newLive;

	}

} // namespace xeres
